<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul,
        ol,
        li {
            list-style: none;
        }

        div {
            width: 600px;
            height: 400px;
            border: 10px solid #333;
            margin: 30px auto;
            display: flex;
            flex-direction: column;

        }

        ul {
            height: 60px;
            display: flex;
        }

        ul>li {
            flex: 1;
            display: flex;
            justify-content: center;
            background-color: pink;
            color: #fff;
            font-size: 40px;
        }

        ul>li.active {
            background-color: orange;
        }


        ol {
            flex: 1;
            position: relative;
        }

        ol>li {
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 100px;
            color: #fff;
            background-color: purple;

            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }

        ol>li.active {
            display: flex;
        }
    </style>
</head>

<body>
    <div>
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>


    <script>
        var btns = document.querySelectorAll('ul>li')
        var tabs = document.querySelectorAll('ol>li')

        btns.forEach(function (item, index) {
            item.setAttribute('index', index)
            item.addEventListener('click', function () {
                btns.forEach(function (item, index) {
                    item.className = ''
                    tabs[index].className = ''
                })
                this.className = 'active'
                tabs[this.getAttribute('index')].className = 'active'
            })
        })
    </script>
</body>

</html>